using System.Collections.Generic;
using Core.GameObjects.Skills;
using Core.GameObjects.Stats;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Core.GameObjects.Entities
{
    /// <summary>
    /// Base Abstract Class That All Entities Derive From
    /// </summary>
    public abstract class Entity : DrawableGameObject
    {
        #region BasicStats
        public Stat Agility { get; protected set; }
        public Stat Intelligence { get; protected set; }
        public Stat Personality { get; protected set; }
        public Stat Endurance { get; protected set; }
        public Stat Willpower { get; protected set; }
        public Stat Strength { get; protected set; }
        public Stat Wisdom { get; protected set; }
        public Stat Luck { get; protected set; }
        public Stat Speed { get; protected set; }
        #endregion

        #region NenStats
        public Stat Emission { get; protected set; }
        public Stat Materialization { get; protected set; }
        public Stat Specialization { get; protected set; }
        public Stat Manipulation { get; protected set; }
        public Stat Reinforcement { get; protected set; }
        public Stat Transformation { get; protected set; }
        #endregion

        #region NenAbilities
        public Stat Ten { get; protected set; }
        public Stat Zetsu { get; protected set; }
        public Stat Ren { get; protected set; }
        public Stat Hatsu { get; protected set; }
        public Stat En { get; protected set; }
        public Stat In { get; protected set; }
        public Stat Gyo { get; protected set; }
        public Stat Ken { get; protected set; }
        public Stat Shu { get; protected set; }
        public Stat Ko { get; protected set; }
        #endregion

        protected Dictionary<Skill, int> _SkillsList;

        public Entity(int id, string name) : base(id, name)
        {
            _SkillsList = new Dictionary<Skill, int>();
        }

        #region Skills
        public int GetSkillValue(Skill skill)
        {
            int value = 0;

            _SkillsList.TryGetValue(skill, out value);

            return value;
        }

        public void AddSkill(Skill skill, int value)
        {
            _SkillsList.Add(skill, value);
        }

        public void RemoveSkill(Skill skill)
        {
            _SkillsList.Remove(skill);
        }
        #endregion

        public void Move(Direction movedir)
        {

            switch (movedir)
            {
                case Direction.Up:
                    _WorldCoordinate.Y--;
                    break;
                case Direction.Down:
                    _WorldCoordinate.Y++;
                    break;
                case Direction.Left:
                    _WorldCoordinate.X--;
                    break;
                case Direction.Right:
                    _WorldCoordinate.X++;
                    break;
                case Direction.UpRight:
                    _WorldCoordinate.Y--;
                    _WorldCoordinate.X++;
                    break;
                case Direction.DownRight:
                    _WorldCoordinate.Y++;
                    _WorldCoordinate.X++;
                    break;
                case Direction.UpLeft:
                    _WorldCoordinate.Y--;
                    _WorldCoordinate.X--;
                    break;
                case Direction.DownLeft:
                    _WorldCoordinate.Y++;
                    _WorldCoordinate.X--;
                    break;
            }
        }

        public override void Draw(SpriteBatch spriteBatch, Point destPoint)
        {
            //Rectangle destRectangle = new Rectangle(destPoint.X, destPoint.Y, _TileSet.TileWidth, _TileSet.TileHeight);

            //int SpriteID = GetFirstAnimationTile() + _Animation.TileAnimationFrame;

            //int tileY = (SpriteID / _TileSet.TilesPerRow);
            //int tileX = (SpriteID % _TileSet.TilesPerRow);
            //Rectangle rectSource = new Rectangle(
            //    (tileX * _TileSet.TileWidth) + _TileSet.HorizontalSpacing * tileX,
            //    (tileY * _TileSet.TileHeight) + _TileSet.VerticalSpacing * tileY,
            //    _TileSet.TileWidth, _TileSet.TileHeight);

            //spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
            //spriteBatch.Draw(_TileSet.TileSetTexture, destRectangle, rectSource, Color.White);
            //spriteBatch.End();

            foreach (GameObject go in _ChildObjects)
            {
                if (go is iDrawable)
                {
                    iDrawable t = (iDrawable)go;

                    t.Draw(spriteBatch, destPoint);
                }
            }
        }

        public override void Update(GameTime gameTime)
        {            
            base.Update(gameTime);
        }
    }
}
